<?php
class model_lhbase_appadminuser extends gdl_components_basemodel
{

    public function primarykey() {
        return 'id';
    }

    public function tableName() {
        return 'lhc_app_admin_user';
    }
	
	public function getInfoArg($arrg=[],$field)
    {
		if(empty($arrg)) return false;
		return $this->select($arrg, $field)->items;
    }

	//检查当前单位下面有没有管理员
	public function checkGroup($groupsid=0)
    {
		if(!$groupsid) return true;
		$authgroupaccess = new model_lhbase_authgroupaccess();
		$groups = $authgroupaccess->selectOne(['groupId'=>$groupsid],'uId');
		return empty($groups['uId']) ? true : false;
    }
	
	/*获取用户可操作单位id
	*platformId int 平台id
	*unitid 部门id
	*
	*/
    public function operating($adminUserId,$adminReg=0,$platformId=0)
    {

        $authuserunits = new model_lhbase_authuserunits();
        $units = new model_lhbase_units();
		
        $unitsAdmin = $this->selectOne(['id'=>$adminUserId],'unitsId,characters,platformId');

        $unitsId = $authuserunits->select(['adminUserId'=>$adminUserId],'unitsId')->items;

	$platformId = $platformId==0 ? $unitsAdmin['platformId'] : $platformId;
        if($unitsAdmin['characters']=='zg'){
		$condition = 'isDelete=1 and platformId='.$platformId;
		if($unitsAdmin['unitsId']){
			$adminUnitsId = $units->operating($platformId,$unitsAdmin['unitsId']);
			$condition .= ' and id in('.implode(',',$adminUnitsId).')';
		}
            $appUserId = $units->select($condition,'id unitsId')->items;
		
            $untId = array_column($appUserId,'unitsId');
            $appUnitsId= empty($appUserId) ? [-1] : $untId;
        } else {
            $appUserId = $this->selectOne(['id'=>$adminUserId],'unitsId');
            $appUnitsId= empty($appUserId) ? [-1] : [$appUserId['unitsId']];
        }

        $userUnitsId = empty($unitsId) ? [-1] : array_column($unitsId,'unitsId');
        $userUnitsId = array_merge($appUnitsId,$userUnitsId);
        return $userUnitsId;
    }
}
